#!/bin/bash
set -e

if [ "${1:0:1}" = '-' ]; then
    set -- influxd "$@"
fi
if [ -d /var/lib/influxdb/data ] && [ -d /var/lib/influxdb/wal ]; then
    echo "start compress series..."  
    echo y |influx_inspect buildtsi -compact-series-file -datadir /var/lib/influxdb/data   -waldir /var/lib/influxdb/wal  
    echo   "exec compress end..."
fi

echo "waiting influxdb start"
#sleep 60
if [ "$1" = 'influxd' ]; then
        echo "start init-influxdb.sh"
        /init-influxdb.sh "${@:2}" &
        echo "end init-influxdb.sh"
       
fi

exec "$@"
